<?php

namespace app\cash\model;

use app\beautiful\model\mall\GoodsModel;
use app\beautiful\model\mall\GoodsSkuModel;
use app\beautiful\model\setting\TableNumberModel;
use app\common\model\CommonModel;
use think\facade\Db;


class ServiceFeeModel extends CommonModel{

    protected  $name = 'beautiful_service_fee';

    protected  $pk   = 'fee_id';
    /**
     * 模型写入前事件（钩子函数）
     */
    public static function onBeforeInsert($model)
    {
        $model->set("add_time", date('Y-m-d H:i:s'));
        $model->set("add_ip", request()->ip());
    }
    public static function list($where,$order=[],$field='*')
    {
        $list = self::where($where)->field($field)->order($order)->select()->toArray();
        foreach ($list as $k=>$v){
            $list[$k]['table_numbers'] = [];
            if($v['table_number_ids']){
                $table_number_ids = array_map('intval',explode(',',$v['table_number_ids']));
                $where['table_number_ids'] = $table_number_ids;
                $where['shop_id'] = $v['shop_id'];
                $re = TableNumberModel::list($where,['id'=>'desc'],1,999);
                $list[$k]['table_numbers'] = $re['list'];
                $list[$k]['table_number_ids'] = $table_number_ids;
            }


        }
        return $list;
    }

}

